package com.wx.md.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wx.md.socket.MyWebSocketClient;
import com.wx.md.tb.AcAnDevice;
import org.java_websocket.drafts.Draft_6455;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.net.URISyntaxException;

@RestController
@RequestMapping("test")
public class TestController   extends ApiController {

    @GetMapping("/selectAll")
    public R selectAll() throws URISyntaxException {
        MyWebSocketClient myWebSocketClient = new MyWebSocketClient(new URI("ws://192.168.31.43:7912/minitouch"));
        String keyd = "{\"operation\":\"d\",\"index\":0,\"pressure\":0.5,\"xP\":0.16358839050131926,\"yP\":0.49875}";
        myWebSocketClient.send(keyd.getBytes());
        String keyu = "{\"operation\":\"u\",\"index\":0,\"pressure\":0.5,\"xP\":0.16358839050131926,\"yP\":0.49875}";
        myWebSocketClient.send(keyu.getBytes());
        String keyc = "{ operation: 'c' }";
        myWebSocketClient.send(keyc.getBytes());


        return success("");
    }

    public static void main(String[] args) throws URISyntaxException {
        URI rul =   new URI("ws://192.168.31.37:7912/minitouch");
        MyWebSocketClient myWebSocketClient = new MyWebSocketClient(rul);
        myWebSocketClient.connect();
        while (!myWebSocketClient.getReadyState().toString().equals("OPEN")) {

        }


        String keyd = "{\"operation\":\"d\",\"index\":0,\"pressure\":0.5,\"xP\":0.16358839050131926,\"yP\":0.49875}";
        myWebSocketClient.send(keyd);
        String   keyc = "{\"operation\":\"c\"}";
        myWebSocketClient.send(keyc);

        String keyu = "{\"operation\":\"u\",\"index\":0,\"pressure\":0.5,\"xP\":0.16358839050131926,\"yP\":0.49875}";
        myWebSocketClient.send(keyu);
        keyc = "{\"operation\":\"c\"}";
        myWebSocketClient.send(keyc);

        keyd = "{\"operation\":\"d\",\"index\":0,\"pressure\":0.5,\"xP\":0.16358839050131926,\"yP\":0.49875}";
        myWebSocketClient.send(keyd);
        keyc = "{\"operation\":\"c\"}";
        myWebSocketClient.send(keyc);

        keyu = "{\"operation\":\"u\",\"index\":0,\"pressure\":0.5,\"xP\":0.16358839050131926,\"yP\":0.49875}";
        myWebSocketClient.send(keyu);
        keyc = " {\"operation\":\"c\"}";
        myWebSocketClient.send(keyc);

        myWebSocketClient.close();
//        String reset = " {  operation: 'r'}";
//        myWebSocketClient.send(reset.getBytes());

    }


}
